package com.vo;

import com.alibaba.fastjson.JSON;

/**
 * Created by Beibei on 19/02/22
 * API响应结果
 */
public class UploadResult<T> {
    private int code;
    private String message;
    private T data;

    public UploadResult setCode(Integer code) {
        this.code = code;
        return this;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public UploadResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public UploadResult setData(T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public static <T>  UploadResult<T> fail(Integer code,T data) {
        UploadResult<T> ret = new UploadResult<T>();
        ret.setCode(code);
        ret.setData(data);
        return ret;
    }

    public static <T>  UploadResult<T> failMessage(Integer code,String msg) {
        UploadResult<T> ret = new UploadResult<T>();
        ret.setCode(code);
        ret.setMessage(msg);
        return ret;
    }
    public static <T>  UploadResult<T> successMessage(Integer code,String msg) {
        UploadResult<T> ret = new UploadResult<T>();
        ret.setCode(code);
        ret.setMessage(msg);
        return ret;
    }

    public static <T> UploadResult<T> success(Integer code,T data) {
        UploadResult<T> ret = new UploadResult<T>();
        ret.setCode(code);
        ret.setData(data);
        return ret;
    }

}